home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
ast_text
/
faqs
/
tcl-faqs
/
part2
< prev
next >
Wrap
Text File
|
1993-06-28
|
34KB
|
1,049 lines
Newsgroups: comp.lang.tcl,comp.answers,news.answers
Path: senator-bedfellow.mit.edu!enterpoop.mit.edu!gatech!howland.reston.ans.net!math.ohio-state.edu!sdd.hp.com!caen!malgudi.oar.net!chemabs!lvirden
From: lwv26@cas.org (Larry W. Virden)
Subject: FAQ: comp.lang.tcl Frequently Asked Questions (2/3)
(Last updated: June 16, 1993)
Message-ID: <tcl.p2_740234997@cas.org>
Followup-To: comp.lang.tcl
Summary: A regular posting of the comp.lang.tcl Frequently Asked Questions
(FAQ) and their answers. This is the second of three parts.
This part covers the how-to questions and answers.
Originator: lwv26@lwv26aws
Keywords: tcl, expect, extended tcl, wish, tk
Sender: lvirden@cas.org
Supersedes: <tcl.p2_737658025@cas.org>
Reply-To: lvirden@cas.org (Larry W. Virden)
Organization: Chemical Abstracts Service
References: <tcl.p1_740234997@cas.org>
Date: Wed, 16 Jun 1993 12:50:38 GMT
Approved: news-answers-request@MIT.Edu
Expires: Wed, 28 Jul 1993 12:49:57 GMT
Lines: 1025
Xref: senator-bedfellow.mit.edu comp.lang.tcl:4758 comp.answers:1025 news.answers:9491
Archive-name: tcl-faq/part2
Version: 3.3
Last-modified: June 16, 1993
Please do not be offended if I neglect to acknowledge your contribution
to this FAQ! I sometimes forget to put an attribution in. I especially
try to add them if it appears that there is further experimentation or
debugging being done though.
For more information concerning Tcl (see "tcl-faq/part1") or
(see "tcl-faq/part3").
Index of questions:
VIII. Questions on building Tcl and friends on your system
Q8A. Is there anywhere I can find help with the details of getting
Tcl to work on my machine?
Q8B. When I am trying to build Tcl, the link step says that some
of the functions Tcl needs are missing.
Q8C. Has anyone built Tcl 6 on an RS/6000 AIX 3.1?
Q8D. Has anyone gotten Tcl to compile under HP-UX?
Q8E. Has anyone gotten Tcl to compile under VMS?
Q8F. What does it take to get Tcl to compile under SCO Unix?
Q8G. When I try to run the tclTest I get format and scan errors
(NeXT, AIX, etc.)
Q8H. When I try to run Tcl V6 tclTest under Irix 4.0.1 I get
lots of errors.
Q8I. Does anyone else have problems with Tcl on a Cray?
Q8J. Does anyone know how to get Tk to run on a SparcBook or other
laptop with a limited number of colors?
Q8K. What does it take to get Tcl/Tk to compile on 386bsd/Linux
or other POSIX/ANSI C systems not already supported?
Q8L. Can anyone help me build tcl 6.7 under NextStep 3.0?
IX. How, in Tcl, can I XXX:
Q9A. get association lists or property lists?
Q9B. call one proc with the multi parameter value returned by
another proc?
Q9C. pass an array into a proc?
Q9D. pipe output of a command back into a Tcl parsing procedure?
Q9E. merge extended Tcl into other programs such as wish or expect?
Q9F. delete a procedure from within a script?
Q9G. get parray to recognize an array variable I have created
via upvar?
Q9H. get more than 7 digits of double precision?
Q9I. grab the command line whenever a non-built-in call is made?
Q9J. get or set an environment variable?
Q9K. use numbers with leading zeroes?
Q9L. find the command line arguments to my application?
Q9M. put comments in my script, for example in a case statement?
Q9N. redirect stdin or stdout safely, including binary data?
Q9O. trap signals, and other more Unix specific functions?
X. How, in Tk, can I XXX:
A. Question on starting Tk applications
Q10.A.1. get my wish application to execute - I just get a wish prompt!
Q10.A.2. ,using a machine with less than 8 bit color, run?
Q10.A.3. set X11 resources for a wish application in an
app-defaults file?
Q10.A.4. specify bitmap patterns on the command line instead of
as a file name?
Q10.A.5. get a Motif user interface?
Q10.A.6. get an OpenLook user interface?
B. Questions on Tk applications and the keyboard
Q10.B.1. change the default class bindings?
Q10.B.2. delete a binding?
Q10.B.3. change a binding while it is being executed?
Q10.B.4. bind the arrow key on my Sun keyboard?
Q10.B.5. get root's mouse bindings to work in my Tk application?
C. Questions on Tk and X11 interactions
Q10.C.1. get an application to also use libXt?
Q10.C.2. change the X11 cursor?
Q10.C.3. raise or lower a window?
Q10.C.4. re-map a withdrawn window id?
Q10.C.5. use Tk in a subwindow of a non-Tk X11 application?
D. Questions on Tk listboxes
Q10.D.1. resize a listbox?
Q10.D.2. select two items that are not adjacent in the listbox at
one time?
Q10.D.3. select items in more than one Tk listbox at a time?
E. Other questions
Q10.E.1. get the name of my own interpreter?
Q10.E.2. get -relief to work on my text widgets?
Q10.E.3. get output from a Tk canvas?
Q10.E.4. fill a canvas which is bounded by lines as opposed to a
shape like a polygon, oval, etc.?
Q10.E.5. create a scrollable window of buttons?
Q10.E.6. pack a text widget so that it can be resized interactively?
Q10.E.7. create a widget with an upper case name?
End of FAQ Index
----------------------------------------------------------------------
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8A- Is there anywhere I can find help with the details of
getting Tcl to work on my machine?
A8A. Glad you asked! Look in the Tcl distribution for the file called
"porting.notes". This will contain a collection of notes that various people
have provided about porting Tcl to various machines and operating systems.
There are also a file called "README" which should be read FIRST - before
doing anything else with the code (this should always be one's first
step with any package). Finally, there is a "changes" file which details
what has changed since the last release - be sure to read this to see
what might need to change in your programs.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8B- When I am trying to build Tcl, the link step says that
some of the functions Tcl needs (such as strtoul and
strerror) are missing.
A8B. Did you run the "config" program first, by doing a "csh ./config" or
equivalent?
Tcl includes equivalents for the following functions and include files
which may not be found on some systems:
dirent.h limits.h stdlib.h string.h
opendir.c strerror.c strstr.c strtol.c strtoul.c
strtod.c
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8C- Has anyone built Tcl 6 on an RS/6000 AIX 3.1?
A8C. See porting notes - especially the note about strtoul.
One user got Tcl to compile with a few minor source modifications
(for example, duplicate case statements for errno and signal symbols in
tclUnixStr.c).
A few other problems arose in the tests. One is caused by AIX printf
not formatting %#x and %#o correctly when the value to be printed is
zero: they print "0x0" and "00" instead of "0" and "0" respectively.
This was reported as not a problem in earlier releases. No fixes have
been posted.
Finally, a problem occurs in open.test. test 13.6 hangs because "cat"
on the RS6000 is unbuffered. A workaround is to change the execution
of "cat" in open.test to do a "cat -u".
Dov Grobgeld <dov@menora.weizmann.ac.il> provided info on creating Tcl
and Tk shared libraries under AIX 3.1.5:
For Tcl:
cc -o tkshar.o *.o -bE:tclshar.exp -bM:SRE -berok -lX11 -lm
ar r libtclshr tclshar.o
For Tk:
cc -o tkshar.o *.o -bE:tkshar.exp -bM:SRE -berok -Ltcl -lX11 -lm -ltclshr
ar r libtkshr tkshar.o
where tckshar.exp and tkshar.exp had lists of the external functions.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8D- Has anyone gotten Tcl to compile under HP-UX?
A8D. See the porting notes.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8E- Has anyone gotten Tcl to compile under VMS?
A8E. Information from jkimball@src.honeywell.com (John Kimball) on
May 4, 1993 was that he had gotten Tcl 6.7 and Tk 3.2 ported to VMS
5.5. See the catalog for the file information.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8F- What does it take to get Tcl to compile under SCO Unix?
A8F. Add a "#undef select" to tkEvent.c, and remove the reference to
TK_EXCEPTION around line 460 of main.c.
Tk uses its own scheme for allocating the border colors for its 3D
widgets, which causes problems when running TK on a system with
"PseudoColor" display class, and a 16-cell colormap.
If you can't go to eight bitplanes, you can instead start the server
with a "-static" (Xsco) or "-analog" (Xsight) option, making the
display class become "StaticColor". This makes the entire colormap
read-only, and it will return the color that most closely maps to the
desired color as possible.
This information is from Keith Amann <Keith_Amann@stortek.com>
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8G- When I try to run the tclTest I get format and scan errors
(NeXT, AIX, etc.)
A8G. That's a problem (scanf/printf) many systems seem to have. Don't
worry too much about it - just don't use these 'advanced' features. If
you're hacking C, you'll have the same problems.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8H- When I try to run Tcl V6 tclTest under Irix 4.0.1 I get
lots of errors.
A8H. There's a bug in the 4.0.1 optimizer that's fixed in 4.0.2.
Compile tclVar.c using -O0 (no optimization).
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8I- Does anyone else have problems with Tcl on a Cray?
A8I. See the porting notes for a set of changes mentioned. Also,
Booker C. Bense <benseb@grumpy.sdsc.edu> reports that version 3.0.1.6
has some real problems with char pointers, causing Tcl to crash. Using
version 3.0.2.1, things are much better, except for a minor formatting
problem and serious problems with scan.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8J- Does anyone know how to get Tk to run on a SparcBook or other
laptop with a limited number of colors?
A8J. On a SparcBook, if you start openwin (the OpenWindows server starting
command) as:
openwin -dev "/dev/fb staticvis"
you get a static visual color model that Tk copes with better than the
default. Some things are ugly, but not as ugly as monochrome.
------------------------------
From: -VIII- Questions on building Tcl and friends on your system
Subject: -Q8K- What does it take to get Tcl/Tk to compile on 386bsd/Linux
or other Posix/ANSI C systems not already supported?
A8K. Patches for 386BSD were posted to comp.lang.tcl back in Nov. 1992 to
alt.sources. See one of the ftp archive sites for this group for them.
Basically, there were some setting of defines and a few places where
const char * had to be used in place of char *.
------------------------------
Subject: -Q8L- Can anyone help me build tcl 6.7 under NextStep 3.0?
A8L. Put #include <sys/time.h> near the top of tclUnixAZ.c.
Thanks to Michael B. Johnson <wave@media.mit.edu>.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9A- association lists or property lists?
A9A. Use Extended Tcl arrays or keyed lists.
For example, if you did a:
keylset ttyFields ttyName tty1a
keylset ttyFields baudRate 57600
keylset ttyFields parity strip
And then an "echo $ttyFields", you'd get:
{ttyName tty1a} {baudRate 57600} {parity strip}
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9B- call one proc with the multi parameter value returned by
another proc?
A9B. Assuming y requires multiple args and x returns multiple words, use
Tcl's eval command "eval y [x]"
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9C- pass an array into a proc?
A9C. Use upvar rather than try to use global variables.
# print elements of an array
proc show arrayName {
upvar $arrayName myArray
foreach element [array names myArray] {
puts stdout "${arrayName}($element) = $myArray($element)"
}
}
set arval(0) zero
set arval(1) one
show arval
Extended Tcl introduces a concept called keyed lists which are arrays
made out of lists of key-value pairs and can be passed by value to routines,
over networks, etc.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9D- pipe output of a command back into a Tcl parsing
procedure?
A9D. For example, to grep a pattern out of a range of files, one might
do:
karl@NeoSoft.com (Karl Lehenbauer) writes:
set files [glob /home/cole/stats/*]
proc parseInfo { site } {
global files
#
# site is chosen from a listbox earlier
#
set in [open [concat "|/usr/bin/grep $site $files"] r]
while {[gets $in line]>-1} {
puts stderr $line
}
catch {close $in}
}
One thing: the matching strings are _not_ returned in directory order.
But what if I want to check the return code AND use the output of
the command? kennykb@dssv01.crd.ge.com (Kevin B. Kenny) writes:
if [catch {exec ls} data] {
# The exec got an error, and $errorCode has its termination status
} else {
# The exec succeeded
}
# In any case, `data' contains all the output from the child process.
Note that Karl Lehenbauer adds that errorCode will be a list containing
three elements, the string "CHILDSTATUS", the process ID of the child,
and the exit status of the child.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9E- merge extended Tcl into other programs such as wish or expect?
A9E. The latest version of extended Tcl, tclX 6.5c, has been enhanced to
make it easier to incorporate into applications.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9F- delete a procedure from within a script?
A9F. rename procedureName ""
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9G- get parray to recognize an array variable I have created
via upvar?
A9G. Right now (June, 1992) upvar doesn't allow you to attach to an
individual element of an array. This is considered a bug by
Mr. Ousterhout and has been place on a bug list.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9H- get more than 7 digits of double precision ?
A9H. Modify the tclExpr.c module to use %lf instead of %g.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9I- grab the command line whenever a non-built-in call is made?
A9I. The procedure "unknown" is called automatically with arguments
containing the command and its arguments for any command that couldn't be
found. In fact, Tcl and Extended Tcl use this feature to provide demand
loaded commands, and even entire libraries.
So by modifying the unknown procedure you can provide your own extended
functionality, or even remove the demand loading capability if you so
desire.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9J- get or set an environment variable?
A9J. By using something like the following.
set olddisplay $env(DISPLAY)
set env(DISPLAY) unix:0
Thanks to "Joel Fine" <joel@cs.berkeley.edu> for the answer.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9K- use numbers with leading zeroes?
A9K. Dave Morriss was recently having problems because he was trying
to do something like:
set index [expr [exec date +%W]%[llength $pop_server_list]]
but during the 9th and 9th week of the year, he got errors - 08 and 09
are not valid octal numbers in Tcl.
Some of the solutions provided were:
From George A. Howlett <gah@att.com>, we got:
set wknum [format "%g" [exec date +%W]]
set index [expr [exec $wknum%[llength $pop_server_list]]
From Fred Feirtag <feirtag@wave.nrl.navy.mil> :
set index [expr (1[exec date +%W]-100)%[llength $pop_server_list]]
From Dan R. Schenck <schendr@Texaco.COM>:
set index [expr [string trimleft [exec date +%W] 0]%[llength $pop_server_list]]
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9L- find the command line arguments to my application?
A9L. If you are using extended Tcl or Expect, you will find the parameters in
the Tcl variable argv as a list. Note that in extended Tcl, the name of
the program is in the Tcl variable programName and NOT in argv[0]. Thanks to
brad@NeoSoft.com (Brad Morrison) and bachww@rtsg.mot.com (Bud Bach) for
this answer.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9M- put comments in my script, for example in a case statement?
A9M. You can't have comments where you have them. Move the comments inside
of the "{" for the case that you want. Your code should read:
case 1 {
-1 {
#
# Cannot find information sought
#
exit 2
}
0 {
#
# Error in arguments
#
exit 1
}
default {
#
# Desired information found
#
exit 0
}
}
Thanks to gwlester@cpu.com (Gerald W. Lester).
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9N- redirect stdin or stdout safely, including binary data?
A9N. With Extended Tcl you can safely do stuff like:
set infp [open "|compress -dc $fileName"]
set outfp [open "|gzip -c $newFileName" w]
copyfile $infp $outfp
Thanks to karl@NeoSoft.com (Karl Lehenbauer) for the code example.
------------------------------
From: -IX- How, in Tcl, can I XXX:
Subject: -Q9O- trap signals, and other more Unix specific functions?
A9O. Extended Tcl offers many of these types of functions. For instance,
extended Tcl has the 'signal' command:
signal action siglist [command]
where action is one of "default", "ignore", "error", "trap", "get",
plus the POSIX "block" and "unblock" actions (available only on
POSIX systems, of course). Siglist is a list of either the symbolic
or numeric Unix signal (the SIG prefix is optional). Command is your
error handler (or a simple {puts stdout "Don't press *that* key!"} :-)
"trap" does what you expect, and I find "error" and "get" to be
extremely useful in interactive programs which demand keyboard
traversal.
Extended Tcl also has things like fork, etc.
Answer by brad@NeoSoft.com (Brad Morrison).
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.1- get my wish application to execute - I just get a
wish prompt! Or I just get error msgs about permission
denied, not found, etc.
A10.A.1. Most systems require a full pathname to the interpreter.
So you cannot start a wish script out as
#! wish -f
Likewise, many Unix systems have a maximum length of characters that you can
put on a #! line. If you exceed this, you do not get the behaviour you
expect. So do not try to put something like:
#! /projects/somethingbig/bin/sun4/wish -f
followed by your wish code. Keep the lines short - under 30 characters is
recommended.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.2- ,using a machine with less than 8 bit color, run?
A10.A.2. Tk doesn't behave very well with less than 8-bit color screens. To
try to use it, find all the places in the Tk/wish source where
DefaultDepthOfScreen is invoked to test the number of bit-planes. Change all
of these to pretend there is just 1 bit-plane, or call a procedure which
monitors a Tcl variable so that it is configurable, and you should be okay.
Another alternative is to see if the server you are using has alternative
visual / color models, such as static visual, etc. One of the alternatives
may allow Tk to work better.
Thanks to "Nathaniel Borenstein" <nsb@thumper.bellcore.com> for this info!
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.3- set X11 resources for a wish application in an
app-defaults file?
A10.A.3. Read the documentation for the option command.
Then you should consider something like the following - assume the program
name is xwf.
The following are two general purpose functions to put into a library:
# envVal envValName
# Looks up the envValName environment variable and returns its
# value, or {} if it does not exists
proc envVal {envValName} {
global env
if [info exists env($envValName)] {return $env($envValName)} {return {}}
}
# loadAppDefaults classNameList ?priority?
# Searches for the app-default files corresponding to classNames in
# the order specified by X Toolkit Intrinsics, and loads them with
# the priority specified (default: startupFile).
proc loadAppDefaults {classNameList {priority startupFile}} {
set filepath "[split [envVal XUSERFILESEARCHPATH] :] \
[envVal XAPPLRESDIR] \
[split [envVal XFILESEARCHPATH] :] \
/usr/lib/X11"
foreach i $classNameList {
foreach j $filepath {
if {[file exists $j/$i]} {
option readfile $j/$i $priority; break
}
}
}
}
# Now, here is what you would put into xwf:
option add Tk.BoldFont "*-lucida sans-Bold-R-Normal-*-100-*" widgetDefault
loadAppDefaults {xwf XWF} userDefault
This sets a program default, then load any defaults specified in the user's
default resources and finally any site or general app-defaults resource.
Of course, you would want to add some xwf command line handling to allow
the user to override things at execution time.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.4- specify bitmap patterns on the command line instead of
just as a file name?
A10.A.4. You can not, at least as of June, 1992.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.5- get a Motif user interface?
A10.A.5. Tk does not currently use the Xt toolkit, so a strict adherence
to Motif via the libXm.a routines is not possible. However, the authors
of Tk prefer the Motif style of user interface, so you will find that Tk
makes quite an attempt to implement a Motif-like interface.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.A.6- get an OpenLook user interface?
A10.A.6. Unfortunately, Tk does not currently use either XView or Xt based
widgets in its user interface, so an OpenLook compliant (or even
similar) interface is probably not easily achievable in the near future.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.B.1- change the default class bindings?
A10.B.1. All default class bindings for Tk widgets are initialized in
$tk_library/tk.tcl. Use this file as a guide to implement new
bindings. For instance, the following code duplicates Button 1's
drag-select facility in Button 3 for all listboxes:
bind Listbox <3> {%W select from [%W nearest %y]}
bind Listbox <B3-Motion> {%W select to [%W nearest %y]}
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.B.2- delete a binding?
A10.B.2. Give an empty-string command to the "bind" invocation. For
example, to disable the Delete key in all entry fields:
bind Entry <Delete> {}
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.B.3- change a binding while it is being executed?
A10.B.3. As of June, 1992, this was not a safe thing to do in Tk. It was
put on the bug list by John Ousterhout to be fixed in a future version.
The solution for now is not to change the bindings, but to change
something in the code they execute. For example, keep a state variable
that indicates which binding you'd like, but always have the binding
call a given procedure. Then that procedure checks the variable and
executes one piece of code or another. Or, you could just make the
binding's command "eval $cmd" and then change the variable "cmd"
depending on your application's state.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.B.4- bind the arrow key on my Sun keyboard?
A10.B.4. You have to call it <Left> rather than <R10>. Under X11, keys are
referred to by their keysym. One can use either xmodmap -pk or the xev
program to determine what the keysym a particular key on a keyboard is
currently generating.
If the keysym that is being used is not known by Tk, you may have to edit
its ks_names.h file. There is a note in this file that indicates that
one should not edit it - but this is where the keysym must be for it to
be recognized.
Thanks to Wayne Christopher <faustus@ygdrasil.CS.Berkeley.EDU> for this
note.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.B.5- get root's mouse bindings to work in my Tk application?
A10.B.5. Some window managers, such as mwm, define mouse button bindings
which cause Tk some problems. Try saving off the window manager's startup
file (something like /.mwmrc for instance) and then copy in a startup
file from a login id that works. Thanks to brad@NeoSoft.com (Brad Morrison)
for this invaluable tip!
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.C.1- get an application to also use libXt?
A10.C.1. Tk2.1 and Xt have different X connections, and XtAppNextEvent will
block is there is nothing coming from the X connection. One way
of fixing this is get the connection number of Tk using
ConnectionNumber(Tk_Display(tk_window));
and using XtAddInput to register this with the Xt event handler. The
callback procedure for XtAddInput wrapper procedure that runs
Tk_OneEvent(1). There might be problems with Tk file sources which
aren't registered with Xt.
Thanks to joe@astro.as.utexas.edu (Joe Wang) for this information.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.C.2- change the X11 cursor?
A10.C.2. Here is a tip from mgc@cray.com (M. G. Christenson).
Look at /usr/include/X11/cursorfont.h for a list of available cursors.
You can use the names in there by removing the 'XC_'.
Here's a little proc I use to make my entire application go 'busy'
while it's doing something. Just call it with the commands you want to
execute, and the watch cursor will be displayed for the time it takes
the commands to complete. Note that any new windows will have their
normal cursor.
proc busy {cmds} {
global errorInfo
set busy {.app .root}
set list [winfo children .]
while {$list != ""} {
set next {}
foreach w $list {
set class [winfo class $w]
set cursor [lindex [$w config -cursor] 4]
if {[winfo toplevel $w] == $w || $cursor != ""} {
lappend busy [list $w $cursor]
}
set next [concat $next [winfo children $w]]
}
set list $next
}
foreach w $busy {
catch {[lindex $w 0] config -cursor watch}
}
update idletasks
set error [catch {uplevel eval [list $cmds]} result]
set ei $errorInfo
foreach w $busy {
catch {[lindex $w 0] config -cursor [lindex $w 1]}
}
if $error {
error $result $ei
} else {
return $result
}
}
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.C.3- raise or lower a window?
A10.C.3. This is on the (semi-infinite) list of things to be done in the future.
If you have the time, please go ahead and add it and submit the code and all
will be grateful.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.C.4- re-map a withdrawn window id?
A10.C.4. Use wm deiconify <windowid>.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.C.5- use Tk in a subwindow of a non-Tk X11 application?
A10.C.5. From faustus@ygdrasil.CS.Berkeley.EDU (Wayne A. Christopher):
[C]reate the Tk toplevel window but don't map it (wm withdraw). Then
re-parent the window to be a subwindow of your other one and then map
it. I have done this when the Tk application is a separate process,
but if it's the same process I think you will get into trouble with the
event loop, since each toolkit wants control.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.D.1- resize a listbox?
A10.D.1. Use wm min/maxsize - in a uniform manner. Here is a resizable listbox:
#!/usr/local/bin/wish -f
wm minsize . 20 20
wm maxsize . 1152 900
pack append . [listbox .l -borderwidth 2 -relief raised] {expand fill}
Doing the same with the text widget brings its resizing under control too.
Thanks to "John C Ellson" <ellson@ontap.att.com).
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.D.2- select two items that are not adjacent in the listbox at
one time?
A10.D.2. See Marc R. Ewing's Listbox.patch for a way to modify Tk to allow
selection of non-contiguous entries.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.D.3- select items in more than one Tk listbox at a time?
A10.D.3. The default for Tk's listbox widget exports its selection as the
X selection. There can only be one of these at a time.
To turn off this behavior in Tk, use the -exportselection false when
you create the listbox. Or, use the
option add *Listbox.exportselection false
command in the beginning of your script.
Thanks to David Herron <david@twg.com> for this tip.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.1- get the name of my own interpreter?
A10.E.1. gah@att.com (George A. Howlett) points us to the winfo manual
page - winfo name . gets the name of the current application.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.2- get -relief to work on my text widgets?
A10.E.2. From Owen Rees <rtor@ansa.co.uk>, we find out that we must:
"[m]ake the border width non-zero as in"
text .t -width 20 -height 20 -relief sunken -borderwidth 4
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.3- get output from a Tk canvas?
A10.E.3. The latest Tk has a save suboption on canvas which allows one
to create a file describing the canvas. The default output is Encapsulated
Postscript, but there is an xpm3 suboption as well.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.4- fill a canvas which is bounded by lines as opposed to a
shape like a polygon, oval, etc.?
A10.E.4. No, you have to at least use a polygon if you want to fill an area
bounded by some lines.
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.5- create a scrollable window of buttons?
A10.E.5. There are at least two ways to do this. First, there is a hypertext
widget that one can get from the Tcl User Contributed Code Archive (see
comp.lang.tcl FAQ part 3 for details) which provides such a facility.
And here is some sample code from
"Michael Moore" <mdm@stegosaur.cis.ohio-state.edu> which shows a way to
do this using just Tk.
#! /bin/wish -f
#
# This demonstrates how to create a scrollable canvas with mutliple
# buttons.
#
# Author : Michael Moore
# Date : November 17, 1992
#
#
# This procedure obtains all the items with the tag "active"
# and prints out their ids.
proc multi_action {} {
set list [.frame.canvas find withtag "active"]
puts stdout "Active Item Ids : "
foreach item $list {
puts stdout $item
}
}
#
# This simulates the toggling of a command button...
# Note that it only works on a color display as is right now
# but the principle is the same for b&w screens.
#
proc multi_activate {num id} {
set tags [.frame.canvas gettags $id]
if {[lsearch $tags "active"] != -1} {
.frame.canvas dtag $id "active"
.frame.canvas.button$num configure \
-background "#060" \
-activebackground "#080"
} else {
.frame.canvas addtag "active" withtag $id
.frame.canvas.button$num configure \
-background "#600" \
-activebackground "#800"
}
}
proc setup {} {
frame .frame
scrollbar .frame.scroll \
-command ".frame.canvas yview" \
-relief raised
canvas .frame.canvas \
-yscroll ".frame.scroll set" \
-scrollregion {0 0 0 650} \
-relief raised \
-confine false \
-scrollincrement 25
pack append .frame \
.frame.scroll {left frame center filly} \
.frame.canvas {left frame center fillx filly}
pack append .\
.frame {left frame center fillx filly}
button .frame.canvas.action \
-relief raised \
-text "Action" \
-command "multi_action"
.frame.canvas create window 1 25 \
-anchor w \
-window .frame.canvas.action
for {set i 2} {$i < 26} {incr i} {
button .frame.canvas.button$i \
-relief raised \
-background "#060" \
-foreground wheat \
-activebackground "#080" \
-activeforeground wheat \
-text "Button $i"
set id [.frame.canvas create window 1 [expr $i*25] \
-anchor w \
-window .frame.canvas.button$i]
.frame.canvas.button$i configure \
-command "multi_activate $i $id"
}
}
setup
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.6- pack a text widget so that it can be resized interactively?
A10.E.6. From Spencer W. Thomas <spencer@med.umich.edu> we find that we need to:
wm minsize . 0 0
text .text
pack append . .text {fill expand}
------------------------------
From: -X- How, in Tk, can I XXX:
Subject: -Q10.E.7- create a widget with an upper case name?
A10.E.7. During a recent revision of Tk, things were changed so that names
beginning with a capital letter are reserved for class names. Specific
instances of widgets must begin with a lower case letter. This enables
X11 resource definitions to distinguish between a class and instance.
------------------------------
End of comp.lang.tcl Frequently Asked Questions (2/3)
*****************************************************
--
:s
:s Larry W. Virden INET: lvirden@cas.org
:s Personal: 674 Falls Place, Reynoldsburg, OH 43068-1614
--
:s
:s Larry W. Virden INET: lvirden@cas.org
:s Personal: 674 Falls Place, Reynoldsburg, OH 43068-1614